package thread.atomic;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author liweimin
 * @date 2021/4/29 16:53
 * @since
 */
public class ArrrayTest {
    static AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(10);

    public static void main(String[] args) {
        for (int a = 0; a < 100; a++) {
            new Thread(() -> {
                for (int i = 0; i < 1000; i++) {
                    atomicIntegerArray.incrementAndGet(i % atomicIntegerArray.length());
                }
            }).start();
        }

        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(atomicIntegerArray);
    }
}
